<?php
include_once('PA_LinksHelper.php');

function render_category_tree($tree, $mode = 'list'){
  switch($mode)
  {
    case 'list':
    {
      $start = '<ul>';
      $lineStart = '<li>';
      $lineEnd = '</li>';
      $end = '</ul>';
      break;
    }
    case 'table':
    {
      $start = '<table>';
      $lineStart = '<tr><td>'; 
      $lineEnd = '</td></tr>';
      $end = '</table>';
      break;
    }
  }
  echo $start;
  if($tree->getName())
  {
    echo $lineStart.'<a href="'.link_to_app('Store', 'categoryItemsList', array('categoryName' => $tree->getName())).'">'.$tree->getName();
    
    if($tree->getLocked()){
      echo ' [ '.($tree->getItemsCount()  ?  : 0).' ]</a>'.$lineEnd;
    }
    else{
      echo ' ( '.($tree->getItemsCount()  ?  : 0).' )</a>'.$lineEnd;
    }
    
    if($tree->getChildCategories()->count() > 0)
    {
      foreach($tree->getChildCategories() as $node)
      {
        render_category_tree($node);
      }
    }
  }
  echo $end;
}